package com.itzhigui.service.impl;

import com.itzhigui.entity.Student;
import com.itzhigui.mapper.StudentMapper;
import com.itzhigui.service.StudentService;
import com.itzhigui.utils.ResponseUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author java1412
 * @since 2023-11-01 17:16:30
 */
@Service
@Transactional
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentMapper studentMapper;

    @Override
    public ResponseUtil findAll() {
        List<Student> studentList = studentMapper.findAll();
        return ResponseUtil.ok("查询所有成功", studentList);
    }

    @Override
    public ResponseUtil findById(Integer id) {
        Student student = studentMapper.findById(id);
        return ResponseUtil.ok("根据id查询成功", student);
    }

    @Override
    public ResponseUtil add(Student student) {
        return studentMapper.add(student).intValue() > 0 ?
                ResponseUtil.ok("添加成功", null) : ResponseUtil.fail("添加失败");
    }

    @Override
    public ResponseUtil update(Student student) {
        return studentMapper.update(student).intValue() > 0 ?
                ResponseUtil.ok("更新成功", null) : ResponseUtil.fail("更新失败");
    }

    @Override
    public ResponseUtil deleteById(Integer id) {
        return studentMapper.deleteById(id).intValue() > 0 ?
                ResponseUtil.ok("删除成功", null) : ResponseUtil.fail("删除失败");
    }

    @Override
    public ResponseUtil deleteByIds(Integer... ids) {
        return studentMapper.deleteByIds(ids).intValue() > 0 ?
                ResponseUtil.ok("批量删除成功", null) : ResponseUtil.fail("批量删除失败");
    }
}
